<style lang="less">
	page{
		background: #f6f6f6;
	}
	.content {
		text-align: center;
		margin-top: 20upx;
		padding: 0 30upx;
		box-sizing: border-box;
		.main-list{
			position: relative;
			background: #FFFFFF;
			box-shadow:0px 8upx 18upx 2upx rgba(221,221,221,0.3);
			border-radius:12upx;
			margin-top: 20upx;
			overflow: hidden;
			.main-list-title{
				display: flex;
				background:rgba(51,51,51,1);
				padding: 10upx 30upx;
				align-items: center;
				justify-content: space-between;
				box-sizing: border-box;
				.main-list-title-fl{
					font-size:26upx;
					font-weight:bold;
					color:rgba(219,194,145,1);
					line-height:36upx;
					width: 60%;
					text-align: left;
				}
				.main-list-title-fr{
					width: 40%;
					text-align: right;
					.time{
						font-size:20upx;
						font-weight:500;
						color:rgba(219,194,145,1);
						line-height:36upx;
					}
					
				}
			}
			.main-list-main{
				padding: 20upx 30upx;
				box-sizing: border-box;
				display: flex;
				.main-list-main-fl{
					width: 45%;
					.fl-img{
						width: 100%;
						height: auto;
					}
					.fl-num{
						display: inline-block;
						text-align: center;
						font-size:20upx;
						font-weight:500;
						color:rgba(219,194,145,1);
						line-height:40upx;
						border:1px solid rgba(219,194,145,1);
						border-radius:20px;
						padding: 0 20upx;
						margin-top: 10upx;
					}
				}
				.main-list-main-fr{
					width: 55%;
					margin-left: 20upx;
					.fr-name{
						text-align: left;
						font-size:22upx;
						font-weight:500;
						color:rgba(51,51,51,1);
						line-height:28upx;
						min-height: 84upx;
						// height: 108upx;
						// overflow:hidden;
						// text-overflow:ellipsis;
						// display:-webkit-box;
						// -webkit-box-orient:vertical;
						// -webkit-line-clamp:3;
					}
					.fr-mian{
						height: 100upx;
						display: flex;
						white-space: nowrap;
						justify-content: flex-start;
						text-align: left;
						margin-top: 10upx;
						.fr-mian-for{
							display: inline-block;
							.fr-mian-img{
								margin-right: 10upx;
								width: 100upx;
								height: 100upx;
								display: inline-block;
							}
						}
						
					}
					.fr-bot{
						text-align: left;
						.fr-bot-fl{
							font-size:20upx;
							font-weight:500;
							color:rgba(153,153,153,1);
							line-height:30upx;
							// overflow:hidden;
							// text-overflow:ellipsis;
							// display:-webkit-box;
							// -webkit-box-orient:vertical;
							// -webkit-line-clamp:3;
						}
						.fr-bot-fr{
							font-size:20upx;
							font-weight:500;
							color:#DBC291;
							line-height:30upx;
						}
					}
				}
			}
		}
		.main-list-pm{
			.main-list-pm-img{
				position: relative;
				.imgture{
					width: 100%;
					height: auto;
				}
			}
			.main-list-pm-bot{
				display: flex;
				padding: 10upx 30upx;
				box-sizing: border-box;
				justify-content: space-between;
				.main-list-title-fl{
					font-size:24upx;
					color:rgba(51,51,51,1);
					line-height:36upx;
					width: 60%;
					text-align: left;
				}
				.main-list-title-fr{
					width: 40%;
					text-align: right;
					.time{
						font-size:20upx;
						font-weight:500;
						color:rgba(153,153,153,1);
						line-height:30upx;
					}
					
				}
			}
		}
		.pos{
			position: absolute;
			bottom: 0;
			left: 0;
			font-size:20upx;
			font-weight:500;
			color:rgba(219,194,145,1);
			line-height:40upx;
			background:rgba(51,51,51,1);
			display: inline-block;
			padding: 0 10upx;
			border-radius:0px 12upx 0px 12upx;
		}
	}
	.notAvailable {
		margin: 70upx 0;
		text-align: center;
		image {
			width: 175upx;
			height: 175upx;
		}
	
		view {
			margin-top: 30rpx;
			font-size: 26upx;
			font-weight: bold;
			color: #999999;
			line-height: 26upx;
		}
	}
</style>
<template>
	<view class="content">
		<view class="notAvailable" v-if="listShow == true">
			<image src="https://static.xpandago.net/wechat/images/notAvailable.png" class="" mode="widthFix"></image>
			<view>暂无数据</view>
		</view>
		<view class="main-list" v-for="(itme,i) in list">
			<view class="main-list-for" v-if="itme.activityType==0">
				<view class="main-list-title">
					<view class="main-list-title-fl">{{itme.giftName}}</view>
					<view class="main-list-title-fr">
						<view class="time">从{{itme.startTime}}</view>
						<view class="time">至{{itme.endTime}}</view>
					</view>
				</view>
				<view class="main-list-main">
					<view class="main-list-main-fl">
						<image v-if="itme.light == 1" src='https://static.xpandago.net/wechat/images/gray_panda@2x.png' class="fl-img" mode="widthFix"></image>
						<image v-else-if="itme.light == 2" src='https://static.xpandago.net/wechat/images/half_panda@2x.png' class="fl-img" mode="widthFix"></image>
						<image v-else-if="itme.light == 3" src='https://static.xpandago.net/wechat/images/ahalf_panda@2x.png' class="fl-img" mode="widthFix"></image>
						<image v-else-if="itme.light == 4" src='https://static.xpandago.net/wechat/images/gold_panda@2x.png' class="fl-img" mode="widthFix"></image>
						<!-- <view class="fl-num">已售:{{itme.total}}</view> -->
						<view class="fl-num" v-if="itme.statisticsDimension==1">已售:{{itme.total}}</view>
						<view class="fl-num" v-else-if="itme.statisticsDimension==2">业绩 ¥ {{itme.count}}</view>
						<view class="fl-num" v-else-if="itme.statisticsDimension==3">销售额 ¥{{itme.totalSales}}</view>
						<view class="fl-num" v-else-if="itme.statisticsDimension==4">销售额 ¥{{itme.totalSales}}</view>
						<view class="fl-num" v-else-if="itme.statisticsDimension==5">销售:{{itme.orderNum}}笔订单</view>
					</view>
					<view class="main-list-main-fr">
						<view class="fr-name">{{itme.giftDetail}}</view>
						<scroll-view class="fr-mian" scroll-x="true">
							<view v-if="itme.goodsPhotoList != '' && itme.goodsPhotoList !=null" class="fr-mian-for" v-for="(list,i) in itme.goodsPhotoList">
								<image :src= "'https://static.xpandago.net'+'/'+list" class="fr-mian-img"></image>
							</view>
						</scroll-view>
						<view class="fr-bot" @tap="guize(itme.giftpackSaleId)">
							<view class="fr-bot-fl">{{itme.note}}</view>
							<view class="fr-bot-fr">点击查看活动规则 >></view>
				        </view>
					</view>
				</view>
				<view class="pos" v-if="itme.status == 1">未开始</view>
				<view class="pos" v-else-if="itme.status == 2">进行中</view>
				<view class="pos" v-else-if="itme.status == 3">已结束</view>
			</view>
			<view class="main-list-pm" v-else-if="itme.activityType == 1" @tap="xiangqing(itme.only)">
				<view class="main-list-pm-img">
					<image :src= "'https://static.xpandago.net'+'/'+itme.activityPicture" class="imgture" mode="widthFix"></image>
					<view class="pos" v-if="itme.status == 1">未开始</view>
					<view class="pos" v-else-if="itme.status == 2">进行中</view>
					<view class="pos" v-else-if="itme.status == 3">已结束</view>
				</view>
				<view class="main-list-pm-bot">
					<view class="main-list-title-fl">{{itme.giftName}}</view>
					<view class="main-list-title-fr">
						<view class="time">从{{itme.startTime}}</view>
						<view class="time">至{{itme.endTime}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import api from '@/common/api';
	export default {
		data() {
			return {
				token:'',
				listShow:false,
				list:[]
			}
		},
		onLoad() {
			let token=this.getQueryVariable('token');
			this.token=uni.getStorageSync('token')
			let code=this.GetQueryString('code');
			console.log(code)
			var pages = getCurrentPages(); // 当前页面
			var beforePage = pages[pages.length - 1]; // 获取当前页面的对象
			var url = beforePage.route //当前页面url
			uni.setStorageSync('url', url);
			console.log(url)
			if(token!=false){
				uni.setStorageSync('token', token);
				this.token=token
				this.getParentWeChatCode()
			}else if(this.token!=null && this.token !='' && this.token != undefined){
				this.getParentWeChatCode()
			}else if(code!=null && code !='' && code != undefined){
				this.loginCode(code)
			}else{
				uni.showToast({
					title: '请先登录！',
					icon: 'none'
				})
				setTimeout(() => {
					uni.reLaunch({
					  url: "/pages/login/loginWechat"
					})
				}, 1000);
			}
		},
		//下拉刷新
		 onPullDownRefresh() {
			this.getParentWeChatCode();
			setTimeout(function () {
				uni.stopPullDownRefresh();  //停止下拉刷新动画
			}, 1000);
		},
		methods: {
			async loginCode(code){
				const [err, res] = await api.loginCode({
						query: {
							code:code
						}
					 });
				 console.log(res)
				 if(res.data.code == 0){
					 let token=res.data.data
					 this.token=token
					 uni.setStorageSync('token', token);
					 this.getParentWeChatCode()
				 }else{
					 uni.showToast({
					 	title: res.data.msg,
					 	icon: 'none'
					 })
					if(res.data.code==100){
						uni.removeStorageSync('token');
						setTimeout(() => {
							uni.reLaunch({
							  url: "/pages/login/loginWechat"
							})
						}, 1000);
					}
				 }
			},
			//获取token与id
			getQueryVariable(variable)
			{
			       var query = window.location.search.substring(1);
			       var vars = query.split("&");
			       for (var i=0;i<vars.length;i++) {
			               var pair = vars[i].split("=");
			               if(pair[0] == variable){return pair[1];}
			       }
			       return(false);
			},
			GetQueryString(name){
			    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
			    var r = window.location.search.substr(1).match(reg);
			    if(r!=null)return  unescape(r[2]); return null;
			},
			async getParentWeChatCode(){
				const [err, res] = await api.giftsale({
					 header:{
						'Content-Type': 'application/json',
						'token': this.token
					 }
				 });
				 console.log(res)
				 if(res.data.code == 0){
					 this.list=res.data.data
					 if(this.list=='' || this.list==null){
						 this.listShow=true
					 }
				 }else{
					 uni.showToast({
					 	title: res.data.msg,
					 	icon: 'none'
					 })
					if(res.data.code==200){
						uni.removeStorageSync('token');
						setTimeout(() => {
							uni.reLaunch({
							  url: "/pages/login/loginWechat"
							})
						}, 1000);
					}
				 }
			},
			guize(id){
				uni.navigateTo({
				  url: "/pages/stimulateGz/stimulateGz?id="+id
				})
			},
			xiangqing(id){
				uni.navigateTo({
				  url: "/pages/stimulate/stimulateInfo?id="+id
				})
			}
		}
	}
</script>
